package com.zhoushihao.class0821;

import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.temporal.TemporalAdjusters;
import java.util.Scanner;

public class Celebrate {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int y1 = sc.nextInt();
        int y2 = sc.nextInt();
//        for (int i = y1; i <= y2; i++) {
//            LocalDate firstDay = LocalDate.of(i, a, 1);
//            int monthDays = firstDay.with(TemporalAdjusters.lastDayOfMonth()).getDayOfMonth();
//            int count = 0;
//            int flag = 0;
//            for (int j = 0; j < monthDays; j++) {
//                LocalDate secondDay = firstDay.plusDays(j);
//                int weekDay = secondDay.getDayOfWeek().getValue();
//                if (weekDay == c && count < b) {
//                    count++;
//                }
//                if (count == b) {
//                    flag = 1;
//                    DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy/MM/dd");
//                    System.out.println(dtf.format(secondDay));
//                    break;
//                }
//            }
//            if (flag == 0) {
//                System.out.println("none");
//            }
//        }
        DayOfWeek dayOfWeek = DayOfWeek.of(c);
        for (int i = y1; i <= y2; i++) {
            LocalDate d = LocalDate.of(i, a, 1);
            d = d.with(TemporalAdjusters.dayOfWeekInMonth(b, dayOfWeek));
            if (d.getMonth().getValue() == a) {
                DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy/MM/dd");
                System.out.println(dtf.format(d));
            } else {
                System.out.println("none");
            }
        }
    }
}
